<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>后台登录</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" th:href="@{/bower_components/bootstrap/dist/css/bootstrap.min.css}">
  <!-- Font Awesome -->
  <link rel="stylesheet" th:href="@{/bower_components/font-awesome/css/font-awesome.min.css}">
  <!-- Ionicons -->
  <link rel="stylesheet" th:href="@{/bower_components/Ionicons/css/ionicons.min.css}">
  <!-- Theme style -->
  <link rel="stylesheet" th:href="@{/dist/css/AdminLTE.min.css}">
  <!-- iCheck -->
  <link rel="stylesheet" th:href="@{/plugins/iCheck/square/blue.css}">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
  <script th:src="@{/layui/layui.js}"></script>
  <script th:src="@{/layui/lay/modules/layer.js}"></script>
  <link rel="stylesheet" th:href="@{/layui/css/modules/layer/default/layer.css}">

</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <a href="#"><b>欢迎来到酒店管理系统</b></a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body">

    <form class="layui-form layui-form-pane" method="post" onsubmit="return false;">
      <div class="layui-form-item">
        <label class="layui-form-label">用户名:</label>
        <div class="layui-input-block">
          <input name="managerName" class="layui-input" type="text" placeholder="请输入用户名"  lay-verify="managerName">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-block">
          <input name="managerPassword" id="password" class="layui-input" type="password"  placeholder="请输入密码" lay-verify="managerPassword">
        </div>
      </div>

      <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        <button class="layui-btn layui-btn-primary" type="reset">重置</button>
      </div>
    </div>

      <div class="layui-form-item">
        <label ><a th:href="@{/toRegister}" class="">注册</a></label>
      </div>
    </form>

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script th:src="@{/bower_components/jquery/dist/jquery.min.js}"></script>
<!-- Bootstrap 3.3.7 -->
<script th:src="@{/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
<!-- iCheck -->
<script th:src="@{/plugins/iCheck/icheck.min.js}"></script>

<script>
    layui.use("form",function () {
        var form = layui.form;

        form.on("submit(formDemo)",function (data) {
            $.ajax({
                url:"/manager/shiroLogin",
                type:"POST",
                data:data.field,
                async:true,
                success:function (text) {
                 if(text == 'ok'){
                     window.location.href = "/toStarter";
                 }else if(text == "UnKnownAccount"){
                     layer.alert("用户不存在");
                   //  window.location.href = "/";
                 }else if(text == "IncorrectPassword"){
                     layer.alert("密码错误");
                     window.location.href = "/";
                 }
                }
            });

        });
        //自定义验证规则
        form.verify({
            managerName: function(value){
                if(value.length < 4){
                    return '请输入至少4位的用户名';
                }
            }, managerPassword: function(value){
                if(value.length < 6){
                    return '内容请输入至少6个字符';
                }
            }
            // ,phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
            // ,email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
        });
    });
</script>

</body>
</html>
